<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let a = Math.floor(Math.random() * 10) + 1
        // while (true) {
        for (i = 0; i < 3; i++) {
            let num = +prompt(`输入猜测的数字(1~10)，一共3次机会,这是第${i + 1}次`)

            if (num > a) {
                alert("数字猜大了")
            } else if (num < a) {
                alert("数字猜小了")
            }
            else {
                alert("恭喜你猜对啦！")
                break
            }
            if (i == 2) {
                alert(`次数耗尽,正确数字是：${a}`)
            }

        }
        alert('游戏结束！')

        // }
    </script>
</body>

</html>